Skip to content

[Submit] Fix regressions from the "Submit to my employer" flow (#94319)#96136

Open
abzokhattab wants to merge 10 commits into
Expensify:mainfrom
abzokhattab:abzokhattab-scope-getpolicyname-92704
Open

[Submit] Fix regressions from the "Submit to my employer" flow (#94319)#96136
abzokhattab wants to merge 10 commits into
Expensify:mainfrom
abzokhattab:abzokhattab-scope-getpolicyname-92704

Conversation

@abzokhattab

@abzokhattab abzokhattab commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Follow-up to #94319 (Submit → "Submit to a friend" / "Submit to my employer"). This PR fixes the regressions reported against that PR, plus one targeted safety change:

1. Details page shows the two submit options (#96085)
The track-expense details page menu still rendered the single "Submit to someone" option, while the whisper (ChatActionableButtons) already split it into "Submit to a friend" / "Submit to my employer". This mirrors that split on the details page, gated behind the same SUBMIT_2026 beta.

2. "Unexpected error" after submitting to a new workspace (#96119)
moveTrackedExpenseToPolicy spread policyParams — which carries a full Onyx policy object used only for optimistic data — into the AddTrackedExpenseToPolicy / CategorizeTrackedExpense request. Non-Blob objects fail FormData serialization on Android, so the write failed, retried to exhaustion, and stamped the failure "Unexpected error" onto the expense preview. The policy object is now stripped from the API payload (it remains available for optimistic Onyx writes).

3. Sticky "Rate not valid" error (#96200) and missing receipt empty state (#96214)
MoneyRequestConfirmationList re-derives its policy via usePolicyForTransaction without the draft policy, so in the zero-workspace "Submit to my employer" flow (destination is a draft workspace in POLICY_DRAFTS) policy resolved to undefined. That broke rate validation (rates read from undefined, so the invalidRate error could never clear) and hid the receipt empty state (isGroupPolicy(undefined) is false). usePolicyForTransaction now falls back to the draft policy from Onyx; real policies always take precedence.

4. Per diem submitted to a Submit workspace → infinite loading (#96212)
Per diem is a Control-plan feature, but nothing stopped a tracked per diem expense from being submitted into a workspace that can't process it. A confirmation guard now blocks it with the existing "You can't move per diem expenses…" error, mirroring the guard in IOURequestEditReportCommon.

5. Infinite skeleton when backing out of the confirmation page (#96117)
On narrow layouts the confirmation screen pre-inserts the destination report under the RHP. For the zero-workspace employer flow the destination is a draft-only report (REPORT_DRAFT), which the report screen can't render — so the device back button revealed an infinite skeleton. The pre-insert readiness check now skips the REPORT_DRAFT fallback, leaving the origin self-DM under the RHP.

6. Scope the draft-workspace name resolution to be targeted and safe (#92704 follow-up)
Replaces the broad oldPolicyName guard change in getPolicyName with a targeted approach: honor the policy argument a caller explicitly passes, and forward the draft transaction policy for the matching participant in IOURequestStepConfirmation. This removes any behavior change for zero-policy users outside the beta.

Fixed Issues

$ #96085
$ #96117
$ #96119
$ #96200
$ #96212
$ #96214
PROPOSAL:

Tests

Prerequisite: account with the SUBMIT_2026 beta, no workspaces, and a self DM.

Details page options (#96085):

  1. Create a manual expense in the self DM, open it, and open the details page from the header.
  2. Verify it shows "Submit to a friend" and "Submit to my employer" (not "Submit to someone").

Back navigation (#96117):

  1. On a narrow layout (Android), tap "Submit to my employer" on the whisper.
  2. On the confirmation page, press the device back button.
  3. Verify you land back on the self DM chat (no infinite skeleton), and the top-left back button behaves normally.

Submit to new workspace (#96119, Android):

  1. Tap "Submit to my employer" and submit the expense.
  2. Return to Inbox, reopen the workspace chat.
  3. Verify no "Unexpected error" appears on the expense preview.

Receipt empty state (#96214):

  1. Create a manual expense without a receipt, tap "Submit to my employer".
  2. Verify the confirmation page shows the receipt empty state (dropzone).

Distance rate (#96200):

  1. Create a distance expense in the self DM, tap "Submit to my employer".
  2. On the confirmation page tap Rate and select the default rate.
  3. Verify the "Rate not valid" error clears.

Per diem guard (#96212):

  1. With a Control workspace with per diem rates, create a per diem expense in the self DM.
  2. Delete the workspace, go back to the self DM, tap "Submit to my employer", then "Create expense".
  3. Verify a clear error is shown and the expense is not submitted (no stuck loading report).
  • Verify that no errors appear in the JS console

Offline tests

Same as tests — the fixes are client-side; the per diem guard and policy resolution work offline.

QA Steps

Same as tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2026-07-19.at.15.17.18.mov
Screen.Recording.2026-07-19.at.13.45.44.mov
Screen.Recording.2026-07-19.at.13.42.33.mov
Screen.Recording.2026-07-19.at.13.35.05.mov
Android: mWeb Chrome
iOS: Native
Screen.Recording.2026-07-19.at.16.06.23.mov
iOS: mWeb Safari
Screen.Recording.2026-07-19.at.16.09.50.mov
MacOS: Chrome / Safari Screenshot 2026-07-19 at 12 39 25
Screen.Recording.2026-07-19.at.13.11.51.mov
Screen.Recording.2026-07-19.at.15.54.01.mov
Screen.Recording.2026-07-19.at.15.21.23.mov

Resolve the confirmation "To" name for a freshly created draft workspace
(zero-workspace "Submit to my employer") via the policy explicitly passed to
getPolicyName instead of broadening the early-bail guard with oldPolicyName,
which affected all zero-policy users. The confirmation now forwards the draft
policy for the matching participant so the name resolves through the normal path.
The track-expense details page menu still showed the single "Submit to
someone" option. Split it into "Submit to a friend" / "Submit to my employer"
behind the SUBMIT_2026 beta, matching the whisper (ChatActionableButtons).
Fixes Expensify#96085.
moveTrackedExpenseToPolicy spread policyParams (which carries a full Onyx
policy object for optimistic data) into the CategorizeTrackedExpense /
AddTrackedExpenseToPolicy request. Non-Blob objects fail FormData
serialization on Android, so the write failed and stamped "Unexpected error"
on the expense preview. Fixes Expensify#96119.
Fall back to POLICY_DRAFTS when no real policy exists so callers that don't
pass policyDraft (e.g. MoneyRequestConfirmationList) resolve a freshly created
draft workspace. Fixes the sticky "Rate not valid" error (Expensify#96200) and the
missing receipt empty state (Expensify#96214) in the zero-workspace "Submit to my
employer" flow.
Add a confirmation guard so a tracked per diem expense can't be moved into a
workspace without per diem support (e.g. a Submit workspace created via
"Submit to my employer"). The submission previously fell through to a request
the backend can't resolve, leaving the report stuck loading. Fixes Expensify#96212.
A draft-only report (the expense chat of a freshly created draft workspace)
can't render as a report screen, so pre-inserting it stranded users on an
infinite skeleton when backing out of "Submit to my employer" before
submitting. Skip the REPORT_DRAFT fallback in the pre-insert readiness check.
Fixes Expensify#96117.
@abzokhattab abzokhattab changed the title [Submit] Fix details-page submit options and scope draft-workspace name resolution [Submit] Fix regressions from the "Submit to my employer" flow (#94319) Jul 16, 2026
…t policy name

getPolicyName no longer bails to "Unavailable workspace" when the caller
explicitly passes a policy, so getReportSections resolves the snapshot
policy's real name for the expense report workspace avatar.
@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/CONST/index.ts 94.81% <ø> (ø)
src/components/MoneyRequestConfirmationList.tsx 94.69% <ø> (ø)
...onfirmationList/hooks/useConfirmationValidation.ts 83.78% <100.00%> (+0.45%) ⬆️
src/hooks/usePolicyForTransaction.ts 100.00% <100.00%> (ø)
src/libs/ReportUtils.ts 86.05% <100.00%> (-1.03%) ⬇️
src/libs/actions/IOU/TrackExpense.ts 79.48% <100.00%> (+0.19%) ⬆️
...es/iou/request/step/IOURequestStepConfirmation.tsx 64.65% <100.00%> (ø)
src/pages/DynamicReportDetailsPage.tsx 58.10% <52.94%> (+0.26%) ⬆️
... and 172 files with indirect coverage changes

…aram

Covers the branches Codecov flagged as uncovered: the new per diem
moveExpensesError guard in useConfirmationValidation and the getPolicyName
change that resolves an explicitly passed policy for draft workspaces.
@abzokhattab
abzokhattab marked this pull request as ready for review July 19, 2026 14:12
@abzokhattab
abzokhattab requested review from a team as code owners July 19, 2026 14:12
@melvin-bot
melvin-bot Bot requested review from ZhenjaHorbach and trjExpensify and removed request for a team July 19, 2026 14:12
@melvin-bot

melvin-bot Bot commented Jul 19, 2026

Copy link
Copy Markdown

@ZhenjaHorbach Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@melvin-bot
melvin-bot Bot removed the request for review from a team July 19, 2026 14:12
@abzokhattab

Copy link
Copy Markdown
Contributor Author

The PR is ready for review @hungvu193

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50cf4ef91b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/libs/ReportUtils.ts
@hungvu193
hungvu193 requested review from hungvu193 and removed request for ZhenjaHorbach July 19, 2026 15:54
@garrettmknight
garrettmknight self-requested a review July 20, 2026 18:30

@garrettmknight garrettmknight left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this looks good from a product perspective and the changes match the behavior I'd expect.

@trjExpensify
trjExpensify removed their request for review July 20, 2026 18:46
@trjExpensify

Copy link
Copy Markdown
Contributor

Thanks, G! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants